/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpaintball;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;

/**
 *
 * @author ondra
 */
public class NetworkServer extends Thread {

    ServerSocket socket;
    ArrayList<NetworkServerThread> threads;

    NetworkServer(int port) {

        threads = new ArrayList();

        try {
            socket = new ServerSocket(port);
        } catch (IOException ex) {
            System.out.println("Cant bind socket");
        }

    }

    public void run() {

        while(true) {
            try {
                NetworkServerThread n = new NetworkServerThread(socket.accept());
                n.start();
                threads.add(n);
                System.out.println("added thread");
            } catch (IOException ex) {
                System.out.println("Cant listen");
            }
        }

    }

}
